#pragma once
#include "rostermanager.h"
#include <string>
#include <list>
#include "disco.h"
#include "discohandler.h"
using namespace gloox;

namespace gloox
{
	class FriendHandler;
}

class FriendInfo
{
public:
	FriendInfo(){}
	~FriendInfo(){}

	std::string		m_name;
	std::string		m_jid;
	std::string		m_state;
	std::string		m_data;
};

typedef std::list<FriendInfo>	FriendList;

class FriendManager : public RosterListener, public DiscoHandler
{
public:
	FriendManager(void);
	~FriendManager(void);
	const Roster& roster(){ return m_roster; }
	const FriendList& friends(){ return m_friends; }
	void registerhandler(FriendHandler* handler) { m_handle = handler; }
	static void G2U(char* src, const char* gb2312);
	static void U2G(char* src, const char* utf8);
public:
	virtual void handleRoster( const Roster& roster );
	virtual void handleRosterError( const IQ& iq );
	virtual void handleItemAdded( const JID& jid );
	virtual void handleItemSubscribed( const JID& jid );
	virtual void handleItemUnsubscribed( const JID& jid );
	virtual void handleItemUpdated( const JID& jid );
	virtual void handleItemRemoved( const JID& jid );
	virtual void handleRosterPresence( const RosterItem& item, const std::string& resource,
		Presence::PresenceType presence, const std::string& msg );
	virtual void handleSelfPresence( const RosterItem& item, const std::string& resource,
		Presence::PresenceType presence, const std::string& msg );
	virtual bool handleSubscriptionRequest( const JID& jid, const std::string& msg );
	virtual bool handleUnsubscriptionRequest( const JID& jid, const std::string& msg );
	virtual void handleNonrosterPresence( const Presence& presence );

	virtual void handleDiscoInfo( const JID& from, const Disco::Info& info, int context );
    virtual void handleDiscoItems( const JID& from, const Disco::Items& items, int context );
    virtual void handleDiscoError( const JID& from, const Error* error, int context );
private:
	FriendList m_friends;
	Roster m_roster;
	FriendHandler*	m_handle;
};

extern FriendManager g_friendmanager;
